package org.gl.training.gwt.server.utils;

import java.util.ArrayList;
import java.util.List;

import org.gl.training.gwt.shared.model.TaskVO;
import org.gl.training.planner.model.Task;

public class TaskVOUtils {

	public static List<TaskVO> getTaskVOs(List<Task> tasks) {
		if (tasks == null) {
			return new ArrayList<TaskVO>();
		}
		List<TaskVO> taskVOList = new ArrayList<TaskVO>();
		for (Task task : tasks) {
			TaskVO taskVO = getTaskVO(task);
			taskVOList.add(taskVO);
		}
		return taskVOList;
	}

	public static TaskVO getTaskVO(Task task) {
		if (task == null) {
			return null;
		}

		TaskVO taskVO = new TaskVO();
		taskVO.setId(task.getId());
		taskVO.setEvent(task.getEvent());
		taskVO.setTime(task.getTime());
		taskVO.setEstimateDuration(task.getEstimateDuration());
		taskVO.setActualDuration(task.getActualDuration());
		taskVO.setComments(task.getComments());
		return taskVO;
	}

	public static Task getTask(TaskVO taskVO) {
		Task task = new Task();
		task.setId(taskVO.getId());
		task.setEvent(taskVO.getEvent());
		task.setTime(taskVO.getTime());
		task.setEstimateDuration(taskVO.getEstimateDuration());
		task.setActualDuration(taskVO.getActualDuration());
		task.setComments(taskVO.getComments());
		return task;
	}
}
